function loading_area(image_url, table, inner_cover)
{
                jQuery(table).html('<div id="cover"></div><div class="loading">'+image_url+'</div>'+jQuery(table).html());
                jQuery("#cover").css("position", "absolute");
                //alert("dsf");
                //alert(jQuery("#cover").css("top"));
                jQuery(".loading img").css("z-index", 200);
                jQuery(".loading img").css("margin-top", (jQuery(inner_cover).height())/2);
                jQuery("#cover").css("top", jQuery(inner_cover).offset().top );
                jQuery("#cover").css("left", jQuery(inner_cover).offset().left );
                jQuery("#cover").css("z-index", 100 );
                jQuery("#cover").css("width", jQuery(inner_cover).width());
                jQuery("#cover").css("height", jQuery(inner_cover).height());
}

function formToJSON( selector )
{
     var form = {};
     $(selector).find(':input[name]:enabled').each( function() {
         var self = $(this);
         var name = self.attr('name');
         if (form[name]) {
            form[name] = form[name] + ',' + self.val();
         }
         else {
            form[name] = self.val();
         }
     });

     return form;
}

function doSelectedAction(action)
{
        // alert($('select.dropdown_action').val());
        value = $('select.dropdown_action').val();
        // alert(value);
        if(value == "non")
        {
                alert("Please select an option !");
                return;
        }
        
        if (!jQuery('#items_list .checkbox').is(':checked'))
        {
		alert("Please select item/items to delete");
		return;
        }
        
        if(value == "delete")
        {
                // var a = true;
                var a = confirm("Delete all selected articles !");
                if(!a) return;
        }
        
        $("#mainForm").attr("action", action);
        $("#mainForm").submit();
}

function previewArticle(url)
{
  $("#modal-content").html("Loading....");
  $("#modal-content").css("width", "800px");
  $("#modal-content").css("height", "500px");
  jQuery.ajax({
    url: url,
    success: function (data){
          $("#modal-content").html(data);
          $("#modal-content").css("width", "780px");
        }
  });    
}

function previewVideo(url)
{
  $("#modal-content").html("Loading....");
  $("#modal-content").css("width", "485px");
  $("#modal-content").css("height", "280px");
  jQuery.ajax({
    url: url,
    success: function (data){
          $("#modal-content").html(data);
          $("#modal-content").css("width", "480px");
        }
  });    
}

function openInsertImage(url)
{
  $("#modal-content").html("Loading....");
  $("#modal-content").css("width", "800px");
  $("#modal-content").css("height", "500px");
  jQuery.ajax({
    url: url,
    success: function (data){
          $("#modal-content").html(data);
          $("#modal-content").css("width", "780px");
        }
  });    
}

function insertImage(picture)
{
    tinyMCE.execInstanceCommand("news_body","mceInsertContent",false,'<img src="'+picture+'" />');
    tinyMCE.execInstanceCommand("article_body","mceInsertContent",false,'<img src="'+picture+'" />');
}

function setDefaultImage(id, url)
{
    $('#article_image_id').attr("value", id);
    $('#default_image').attr("src", url);
}

function uploadMore()
{
                // $("#upload-image-items").html($("#upload-image-items").html);
                $($('#first-image-content').html()).insertBefore('#upload-more');
}

jQuery(document).ready(function() {
		
                // alert("sdfsdfsfsf");
                
                jQuery('#items_list .checkbox.select-all').click(function() {
                                //alert(jQuery('#articles .checkbox.select-all').is(':checked'));
                                jQuery("#items_list .checkbox").attr("checked", jQuery('#items_list .checkbox.select-all').is(':checked'));										      
                });
                
                jQuery('.published').click(function() {
                                //alert(jQuery('#articles .checkbox.select-all').is(':checked'));
                                //jQuery('.published').html('<div class="loading"><%= image_tag "loading_ajax.gif" %></div>');
                                this.innerHTML = '<div class="published_loading"><img src="/images/published_ajax.gif" border=0 /></div>';
                              });
                
                
                
                jQuery('input.tinymce').tinymce({
                                // Location of TinyMCE script
                                script_url : '/javascripts/tiny_mce/tiny_mce.js',
                                // General options
                                mode : "textareas",
                                theme : "advanced",
                                plugins : "autolink,lists,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
                        
                                // Theme options
                                theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
                                theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
                                theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
                                theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,spellchecker,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,blockquote,pagebreak,|,insertfile,insertimage",
                                theme_advanced_toolbar_location : "top",
                                theme_advanced_toolbar_align : "left",
                                theme_advanced_statusbar_location : "bottom",
                                theme_advanced_resizing : true,
                                width: 800,
                                height: 500,
                                convert_urls : false,
                        
                                // Skin options
                                skin : "o2k7",
                                skin_variant : "silver",
                        
                                // Example content CSS (should be your site CSS)
                                content_css : "css/example.css",
                        
                                // Drop lists for link/image/media/template dialogs
                                template_external_list_url : "js/template_list.js",
                                external_link_list_url : "js/link_list.js",
                                external_image_list_url : "js/image_list.js",
                                media_external_list_url : "js/media_list.js",
                        
                                // Replace values for the template plugin
                                template_replace_values : {
                                        username : "Some User",
                                        staffid : "991234"
                                }

                });
                
                

                jQuery(document).ready(function () {
                  jQuery('.preview-but').fancybox({
                        'modal' 		: false,
                        'hideOnOverlayClick' 	: 'true',
                        'hideOnContentClick' 	: 'true',
                        'enableEscapeButton' 	: true,
                        'showCloseButton' 	: true
                    });
                  
                    jQuery('.preview-video-but').fancybox({
                        'modal' 		: false,
                        'hideOnOverlayClick' 	: 'true',
                        'hideOnContentClick' 	: false,
                        'enableEscapeButton' 	: true,
                        'showCloseButton' 	: true
                    }); 
                });
							    
		
                jQuery(document).ready(function () {
                  jQuery('#insert-image-but').fancybox({
                        'modal' 		: false,
                        'hideOnOverlayClick' 	: 'true',
                        'hideOnContentClick' 	: 'true',
                        'enableEscapeButton' 	: true,
                        'showCloseButton' 	: true
                    }); 
                });
                
                
                jQuery("a.fx[href$='gif']").fancybox();
                jQuery("a.fx[href$='jpg']").fancybox();
                jQuery("a.fx[href$='png']").fancybox(); 
                

});
        
                                                        
